﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using graphical_function_explorer.FunctionPreparer;

namespace graphical_function_explorer.Forms
{
    public partial class NewFunctionForm : Form
    {
        private MainForm mainForm;
        private FormatController formatController;
        private ErrorInformer errorInformer;

        private char mainVar;
        private string equation;

        public NewFunctionForm(MainForm mainForm)
        {
            InitializeComponent();

            this.mainForm = mainForm;
            formatController = new FormatController();
            errorInformer = new ErrorInformer(this.label_ErrorInformer);

            this.comboBox_MainVar.Items.Add(ItemProvider.horizAxisVar);
            this.comboBox_MainVar.Items.Add(ItemProvider.vertAxisVar);

            this.Visible = true;
        }

        private void button_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button_Ok_Click(object sender, EventArgs e)
        {
            mainVar = Convert.ToChar(this.comboBox_MainVar.Text);
            equation = formatController.ApplyConstraints(mainVar, this.textBox_Equation.Text);

            if (!errorInformer.FindErrors(mainVar, equation))
            {
                ItemProvider.AddFunction(mainVar, equation);

                mainForm.ApplyNewFunction();

                this.Close();
            }
        }
    }
}
